﻿using System;
namespace MyTime.ProviderFactory.Entities
{
    public class TimeItemBOBO
    {
        public TimeItemBOBO(string task, DateTime startTime)
        {
            this.Task = task;
            this.StartTime = startTime;
            this.EndTime = DateTime.Now;
            this.Current = true;
        }

        public TimeItemBOBO(string task, DateTime startTime, DateTime endTime)
        {
            this.Task = task;
            this.StartTime = startTime;
            this.EndTime = endTime;
        }

        public TimeItemBOBO(string task, DateTime startTime, DateTime endTime, bool noEndDate)
        {
            this.Task = task;
            this.StartTime = startTime;
            this.EndTime = endTime;
            this.Current = noEndDate;
        }
        public string Task { get; private set; }
        public DateTime StartTime { get; private set; }
        public DateTime EndTime { get; private set; }
        public TimeSpan TotalTime { get { return EndTime.Subtract(StartTime); } }
        public int Week { get { return GetWeekNumber(StartTime); } }
        public bool Current { get; private set; }

        private int GetWeekNumber(DateTime date)
        {
            return System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
            //return weekNum;
        }
        public static ITimeItem Parse(string[] cols)
        {
            if (cols.Length != 3)
                throw new ArgumentOutOfRangeException("cols", cols, "columns should be task, startTime, endTime");
            string task = cols[0];
            DateTime startTime = DateTime.Parse(cols[1]);
            DateTime endTime = DateTime.Now;
            bool colHasNoEndDate = string.IsNullOrEmpty(cols[2]);
            if (!colHasNoEndDate)
                endTime = DateTime.Parse(cols[2]);
            return null; // new TimeItem(task, startTime, endTime, colHasNoEndDate);
        }
    }
}
